#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>


int main(int argc, char *argv[])
{
    int sock;
    struct sockaddr_in serv_addr;
    char message[30];
    int str_len;

    sock = socket(PF_INET, SOCK_STREAM, 0);
    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = inet_addr(argv[1]);
    serv_addr.sin_port = htons((uint16_t)atoi(argv[2]));

    connect(sock, (const struct sockaddr *)&serv_addr, sizeof(serv_addr));
    str_len = (int)read(sock, message, sizeof(message) - 1);

    printf("%d\n", str_len);
    printf("服务器传回来的结果: %s\n", message);
    close(sock);
    return 0;
}
